package com.ma.settings;

import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.ma.BuildConfig;
import com.ma.R;

import java.io.File;

import base.BaseActivity;
import utils.ActivityStack;

public class SettingsActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
    }

    public void about(View view) {

        startActivity(AboutActivity.class);
    }

    public void argeen(View view) {
        startActivity(ArgeenActivity.class);
    }

    public void feedback(View view) {
        startActivity(UserFeedbackActivity.class);
    }

    public void update(View view) {


        startActivity(VersionUpdateActivity.class);
    }

    public void chagePwd(View view) {
        startActivity(ChangPwdActivity.class);

    }


    public void systemInit(View view) {

        startActivity(SystemInitActivity.class);
    }

    public void share(View view) {

        try {
            PackageInfo pInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), PackageManager.GET_META_DATA);
            String appName = "";
            appName = this.getPackageManager().getApplicationLabel(pInfo.applicationInfo).toString();
            File apkFile = new File(pInfo.applicationInfo.sourceDir);

            if (!apkFile.exists()) {
                toast( "文件不存在");
                return;
            }


            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("*/*");
            intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_name));


            Uri uri;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                uri = FileProvider.getUriForFile(this  , "com.ma.fileprovider", apkFile);
            } else {
                uri = Uri.fromFile(apkFile);
            }

            intent.putExtra(Intent.EXTRA_STREAM, uri);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();

        }

    }

    public void exit(View view) {

        ActivityStack.get().exit();
    }
}
